﻿namespace Raven
{
    public interface TriggerRegion
    {
        bool isTouching(Vector2 EntityPos, Fix EntityRadius);
    }

    public class TriggerRegionCircle : TriggerRegion
    {
        //the center of the region
        private Vector2 _pos;

        //the radius of the region
        private Fix _radius;

        public TriggerRegionCircle(Vector2 pos, Fix radius)
        {
            _pos = pos;
            _radius = radius;
        }

        public bool isTouching(Vector2 EntityPos, Fix EntityRadius)
        {
            return (_pos - EntityPos).sqrMagnitude < (EntityRadius + _radius) * (EntityRadius + _radius);
        }
    }

    public class TriggerRegionRectange : TriggerRegion
    {
        //the center of the region
        private InvertedAABBox2D _trigger;

        public TriggerRegionRectange(Vector2 topLeft, Vector2 bottomRight)
        {
            _trigger = new InvertedAABBox2D(topLeft, bottomRight);
        }

        public bool isTouching(Vector2 pos, Fix EntityRadius)
        {
            InvertedAABBox2D Box = new InvertedAABBox2D(new Vector2(pos.x-EntityRadius, pos.y-EntityRadius),
            new Vector2(pos.x+EntityRadius, pos.y+EntityRadius));

            return Box.isOverlappedWith(_trigger);
        }
    }
}